package com.richard.base.route

import android.content.Context
import android.os.Parcelable
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import java.io.Serializable

/**
 ***************************************
 * 项目名称:Giggle
 * @Author wuzhiguo
 * 邮箱：wuzhiguo@ksjgs.com
 * 创建时间: 2020/7/14     4:46 PM
 * 用途:
 ***************************************
 */


/**
 * A container that contains the roadmap 二次封装
 * ，所有的方法均来自于 Postcard
 */
class KsPostcard internal constructor(path: String?) {
    private val postcard: Postcard = KsRouter.thirdRouter.build(path)
    val router: ARouter
        get() = KsRouter.thirdRouter

    fun withString(key: String?, value: String?): KsPostcard {
        postcard.withString(key, value)
        return this
    }

    fun withBoolean(key: String?, value: Boolean): KsPostcard {
        postcard.withBoolean(key, value)
        return this
    }

    fun withShort(key: String?, value: Short): KsPostcard {
        postcard.withShort(key, value)
        return this
    }

    fun withInt(key: String?, value: Int): KsPostcard {
        postcard.withInt(key, value)
        return this
    }

    fun navigation(): Any { //加上来源，下个页面可以用来统计使用
        return withString(
            RouterDelegate.getCurrentActivityStatisticKey(),
            RouterDelegate.getCurrentActivityStatisticName()
        ).navigation(null)
        //        return navigation(null);
    }

    fun navigation(context: Context?): Any { //        withString(GlobalConstant.KEY_FROM_ACTIVITY, BridgeDelegate.getInstance().currentActivityStatisticName());
        return postcard.navigation(context, null)
    }

    fun withSerializable(key: String?, value: Serializable?): KsPostcard {
        postcard.withSerializable(key, value)
        return this
    }

    fun withLong(key: String?, value: Long): KsPostcard {
        postcard.withLong(key, value)
        return this
    }

    fun withParcelable(key: String?, value: Parcelable?): KsPostcard {
        postcard.withParcelable(key, value)
        return this
    }

    fun withFlags(flag: Int): KsPostcard {
        postcard.withFlags(flag)
        return this
    }

    fun withTransition(enterAnim: Int, exitAnim: Int): KsPostcard {
        postcard.withTransition(enterAnim, exitAnim)
        return this
    }

    fun navigation(
        mContext: Context?,
        navigationCallback: NavigationCallback?
    ) {
        postcard.navigation(mContext, navigationCallback)
    }

    @JvmOverloads
    fun navigation(
        mContext: Context?,
        requestCode: Int,
        callback: NavigationCallback? = null
    ) { //        withString(GlobalConstant.KEY_FROM_ACTIVITY, BridgeDelegate.getInstance().currentActivityStatisticName());
        router.navigation(mContext, postcard, requestCode, callback)
    }

}